﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinApp.Until;

namespace WinApp.ViewModel
{
    public class CbtPlayModel
    {
        public static bool SavePdfData(AttemptedDetailPdfPutData inpDto, int enrollmentId, int StructureId)
        {
            var strResult = WebApiHelper.PostWebAPI("api/Admin/AttemptedDetail/SavePdfData" + "?enrollmentId=" + enrollmentId + "&structureId=" + StructureId, inpDto);
            bool.TryParse(strResult, out bool result);
            return result;
        }

        public static CbtReadMp4Data ReadMp4Data(int learningStatuTableId)
        {
            CbtReadMp4Data cbtReadMp4Data = new CbtReadMp4Data();
            var resultStr = WebApiHelper.GetWebAPI("api/Admin/AttemptedDetail/ReadData?learningStatuTableId=" + learningStatuTableId);
            if (!resultStr.IsNullOrEmpty())
            {
                // 去除开头和末尾的引号
                resultStr = resultStr.Trim('"');
                resultStr = resultStr.Replace("\\", "");

                cbtReadMp4Data = JsonConvert.DeserializeObject<CbtReadMp4Data>(resultStr);
            }
            return cbtReadMp4Data;

         
        }
    }
    public class CbtReadMp4Data
    {
        public int LessonAttemptedId { get; set; }
        public int LearningStatuTableId { get; set; }
        public string StudyName { get; set; }
        public string TotalSize { get; set; }
        public int TotalCount { get; set; }
        public int CurrentProgress { get; set; }
        public string Message { get; set; }

    }

    public class AttemptedDetailPdfPutData
    {
        public int LessonAttemptedId { get; set; }

        public int LearningStatuTableId { get; set; }

        ///// <summary>
        ///// 和Enrollment表的LearningStatu的含义对应. 是否完成
        ///// pdf就是当前页码==总页码. mp4就是end结束
        ///// </summary>
        //public int LearningStatu { get; set; }

        /// <summary>
        /// pdf的名字,mp4的名字
        /// </summary>
        public string StudyName { get; set; }
        /// <summary>
        /// 资源的大小,比如pdf是3456kb
        /// </summary>
        public string TotalSize { get; set; }

        /// <summary>
        /// 长度,pdf就是总页数,mp4就是总时间(秒值)
        /// </summary>
        public int TotalCount { get; set; }
        /// <summary>
        /// 当前学习进度,pdf就是当前页码,mp4就是当前秒值
        /// </summary>
        public int CurrentProgress { get; set; }
        public string Message { get; set; }
    }

    public class CbtPlayInputDto
    {
        public int CourseUnitType { get; set; }

        public int LessonAttemptedId { get; set; }

        public int LearningStatuTableId { get; set; }

        public int StructureId { get; set; }

        public int EnrollmentId { get; set; }

        public int CourseId { get; set; }
        public string StructureName { get; set; }
        public int CourseUnitId { get; set; }

        public string CourseUnitLanuchPath { get; set; }


        #region PDF or Mp4

        /// <summary>
        /// 文件名称
        /// </summary>
        public string StudyName = "";

        public string Message = "";

        public int TotalCount = 10;

        public long TotalSize = 0;

        public int CurrentProgress = 1;

        #endregion
    }

    public class PreConditionLessonOutputDto
    {
        public bool IsAnd { get; set; }
        public List<LessonInfo> LessonInfoList = new List<LessonInfo>();
    }
    public class LessonInfo
    {
        public string LessonName { get; set; }

        /// <summary>
        /// 参考Enrollment表的LearningStatus字段含义
        /// </summary>
        public int LearningStatu { get; set; }
    }

    public class SourseDeviceType
    {
        public const int MobileOnLine = 1;// 通过移动端APP 在线进行学习
        public const int Browser = 2;    // 通过浏览器学习，包括移动端浏览器学习与web 端浏览器学习
        public const int MobileOffLine = 3;// 移动端APP　离线学习
        public const int ForceComplete = 4;
        public const int WinAppOnLine = 5;//win exe在线；
        public const int WinAppOffLine = 6;//win exe离线；
    }
}
